package com;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Sai
 * Created by Sai on 2019-03-15.
 *
 *
 * @JsonbProperty - 用于指定自定义字段名称
 * @JsonbTransient - 当我们想要在反序列化/序列化期间忽略该字段时
 * @JsonbDateFormat - 当我们想要定义日期的显示格式时
 * @JsonbNumberFormat - 用于指定数值的显示格式
 * @JsonbNillable - 用于启用空值的序列化
 */

public class PinfoDTO {
    private String name;
    private String userid;
    private String email;
    private String phone;
    private String wechat;
    private String qq;
    private String weibo;
    private String faculty_title;


    private Map<String,String> errors=null;

    public PinfoDTO() {
        this.name="";
        this.userid="";
        this.email="";
        this.phone="";
        this.wechat="";
        this.qq="";
        this.weibo="";
        this.faculty_title="";
        this.errors=new HashMap<String, String>();
    }

    public boolean edit(){
        boolean flag=true;
        if(this.name.equals("")){
           flag=false;
           this.name="";
           this.errors.put("errename","用户名不能为空");
        }
        if(flag){
            //将信息写入user。txt文件中，如有无填写的项，用" “代替
            try {
                System.out.println(name);
                OutputStreamWriter writer=new OutputStreamWriter(new FileOutputStream("User.txt"),"UTF-8");
                writer.append(name+",");
                writer.append(userid+",");
                writer.append(email+",");
                writer.append(phone+",");
                writer.append(wechat+",");
                writer.append(qq+",");
                writer.append(weibo+",");
                writer.append(faculty_title+"\n");
                writer.close();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return flag;
    }

    public String getErrMsg(String key){
        String value=this.errors.get(key);
        //若无错误信息，返回空值
        return value==null?"":value;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getWechat() {
        return wechat;
    }

    public void setWechat(String wechat) {
        this.wechat = wechat;
    }

    public String getQq() {
        return qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public String getWeibo() {
        return weibo;
    }

    public void setWeibo(String weibo) {
        this.weibo = weibo;
    }

    public String getFaculty_title() {
        return faculty_title;
    }

    public void setFaculty_title(String faculty_title) {
        this.faculty_title = faculty_title;
    }

    public Map<String, String> getErrors() {
        return errors;
    }

    public void setErrors(Map<String, String> errors) {
        this.errors = errors;
    }
}